package thread;
public class ThreadDemo6 {

    public static void main(String[] args) {
        Thread t = new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 3; i++) {
                    System.out.println("hello");
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
            }
        },"mythread");
        //线程之间的"抢占式执行"(很重要)
        t.start();
        while(true){
            try {
                Thread.sleep(1000);
                //如果t的run没跑就是false
                //如果正在跑 就是true
                //如果跑完了 也是false
                System.out.println(t.isAlive());
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
